<template>
	<view class="hospital-serve page">
		<UserDate :showDate='showDate' @changeUser='onChangeUser' @changeDate='onChangeDate'></UserDate>
		<view class="hospital-serve-history">
			<view v-for="(item,index) in [{listData}]" :key="index" class="card">
				<view class="title u-border-bottom">
					<view class="left">
						<text class="iconfont icon-baogaoguanli_huaban1"></text>
						<text>收据号{{item.jssjh||''}}</text>
					</view>
					<view class="right"></view>
				</view>
				<view class="main flexR">
					<view class="left" v-if="fromPage==='evaluate'">
						<view class="row" v-for="cItem in cardLabelEv" :key='cItem.fKey'><text>{{cItem.label}}</text>{{item[cItem.key]||''}} </view>
						<view class="position-right" v-if="item.whetherCompleted==='0'">
							<image src="../../../static/images/imgs/evaluate.svg" mode="scaleToFill"></image>
						</view>
					</view>
					<view class="left" v-else>
						<view class="row" v-for="cItem in cardLabel" :key='cItem.fKey'><text>{{cItem.label}}</text>{{item[cItem.key]||''}} </view>
					</view>
					<view class="right" @click="toPage(item)">
						<u-icon name="arrow-right" color="#B5B5B5"></u-icon>
					</view>
				</view>
				<view class="div-cut"></view>
			</view>
			<u-empty text='暂无待缴费信息' mode="list" v-if="!load&&listData.length===0"></u-empty>
		</view>
		<Load :load="load" />
	</view>
</template>

<script>
	import { mapGetters } from 'vuex'
	import UserDate from '@/components/UserInfo/user-date.vue'
	import { themeColorLight } from '@/static/js/theme.js'
	import { getRegistered, getEvaluateRegistered } from '@/api/home.js'
	import Load from '@/components/Load/index.vue'
	import {defaultDate} from '@/common/js/default-date.js'
	export default {
		components: { UserDate, Load },
		data() {
			return {
				load:true,
				fromPage:null,
				listData:[{}],
				showDate:false,
				cardLabelEv:[
					{
						label:'科室：',
						key:'ksmc',
						fKey:'label11'
					},
					{
						label:'医生：',
						key:'ysmc',
						fKey:'label21'
					},
					{
						label:'挂号日期：',
						key:'ghrq',
						fKey:'label31'
					}
				],
				cardLabel:[
					{
						label:'开方科室：',
						key:'ksmc',
						fKey:'label11'
					},
					{
						label:'开方医生：',
						key:'ysmc',
						fKey:'label21'
					},
					{
						label:'挂号日期：',
						key:'ghrq',
						fKey:'label31'
					}
				],
				queryDate:''
			}
		},
		computed:{
			...mapGetters(['userInfo'])
		},
		async onLoad(op) {
			if(op.fromPage==='evaluate'){
				this.showDate = false
				uni.setNavigationBarTitle({
					title: '就医评价'
				});
			}else if(op.fromPage==='electronic'){
				this.showDate = true
				uni.setNavigationBarTitle({
					title: '电子病例'
				});
			}else {
				uni.setNavigationBarTitle({
					title: '门诊缴费'
				});
			}
			this.fromPage = op.fromPage||null
			this.queryDate = defaultDate
			await this.$onLaunched;
			this.initData()
		},
		methods: {
			toPage(item){
				if(this.fromPage==='evaluate'){
					let res = JSON.stringify(item)
					uni.navigateTo({
						url:'/pages/Home/Evaluate/detail?paperId=' + item.paperId +'&whetherCompleted=' + item.whetherCompleted
						+'&params=' + res
					})
				}else if(this.fromPage==='electronic'){
					uni.navigateTo({
						url:'/pages/SmartHospital/ElectronicCase/index?ghxh=' + item.ghxh
					})
				}else{
					uni.navigateTo({
						url:`/pages/Service/OutpatientServe/prescription?serialNumber=${item.ghxh}&settlementMark=0`
					})
				}
			},
			initData(){
				if(!this.userInfo.patId){
					uni.navigateTo({
						// url:'/pages/Login/index'
						url:'/pages/Login/addPatient'
					})
					return
				}
				this.load = true
				if(this.fromPage==='evaluate'){ //从评价过来
					let params = {
						patid: this.userInfo.patId,
					}
					getEvaluateRegistered(params).then(data => {
						this.load = false
						this.listData = data||[]
					}).catch(e => {
						this.listData = []
						this.load = false
					})
				}else if(this.fromPage==='electronic'){ //从电子病例过来
					let params = {
						patid: this.userInfo.patId,
						...this.queryDate
					}
					getRegistered(params).then(data => {
						this.load = false
						this.listData = data||[]
					}).catch(e => {
						this.listData = []
						this.load = false
					})
				}else{
					let params = {
						patid: this.userInfo.patId,
						sfcf:1, // 是否有处方 空值忽略 1仅查询有待缴费处方的挂号 2仅查询有已缴费处方的挂号
					}
					getRegistered(params).then(data => {
						this.load = false
						this.listData = data||[]
					}).catch(e => {
						this.listData = [{}]
						this.load = false
					})
				}
			},
			onChangeUser(){
				this.initData()
			},
			onChangeDate(val){
				this.queryDate = val
				this.initData()
			}
		}
	}
</script>

<style lang="scss" scoped>
	$dx:120rpx;
	.hospital-serve{
		height: calc(100vh);
		background-color: $uni-bg-color;
		&-history{
			height: calc(100vh - 200rpx);
			overflow: scroll;
			.main{
				>.left{
					position: relative;
					.position-right{
						position: absolute;
						top: 10rpx;
						right: 10rpx;
						height: $dx;
						width: $dx;
						>image{
							width: 100%;
							height: 100%;
						}
					}
				}
			}
		}
	}
</style>
